package com.nakamachizu.model;

import java.io.Serializable;
import java.util.Date;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.InverseModelListRef;
import org.slim3.datastore.Model;
import org.slim3.datastore.Sort;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Query.SortDirection;
import com.nakamachizu.meta.LandMarkDataMeta;
import com.nakamachizu.meta.LineDataMeta;
import com.nakamachizu.meta.MemberDataMeta;

@Model
public class MapData implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;

    private Integer schemaVersion = 1;
    
    @Attribute(persistent = false)
    private InverseModelListRef<LandMarkData, MapData> landMarkDataListRef =
        new InverseModelListRef<LandMarkData, MapData>(LandMarkData.class, LandMarkDataMeta.get().mapDataRef, this,
                new Sort("entryDate", SortDirection.ASCENDING));
    
    @Attribute(persistent = false)
    private InverseModelListRef<MemberData, MapData> memberDataListRef =
        new InverseModelListRef<MemberData, MapData>(MemberData.class, MemberDataMeta.get().mapDataRef, this,
                new Sort("entryDate", SortDirection.ASCENDING));
    
    @Attribute(persistent = false)
    private InverseModelListRef<LineData, MapData> lineDataListRef =
        new InverseModelListRef<LineData, MapData>(LineData.class, LineDataMeta.get().mapDataRef, this,
                new Sort("entryDate", SortDirection.ASCENDING));
    
    private String accessKey;
    
    private String adminMailAddress;
    
    private Date expire;
    
    private String viewPassword;
    
    private String title;
    
    private String lineType;
    
    private String fromMailAddress;
    
    private String accessLevel;

    /**
     * Returns the key.
     *
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * Sets the key.
     *
     * @param key
     *            the key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * Returns the version.
     *
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version.
     *
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * Returns the schema version.
     *
     * @return the schema version
     */
    public Integer getSchemaVersion() {
        return schemaVersion;
    }

    /**
     * Sets the schema version.
     *
     * @param schemaVersion
     *            the schema version
     */
    public void setSchemaVersion(Integer schemaVersion) {
        this.schemaVersion = schemaVersion;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        MapData other = (MapData) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        return true;
    }

    public String getViewPassword() {
        return viewPassword;
    }

    public void setViewPassword(String viewPassword) {
        this.viewPassword = viewPassword;
    }

    public Date getExpire() {
        return expire;
    }

    public void setExpire(Date expire) {
        this.expire = expire;
    }


    /**
     * @return the landMarkDataListRef
     */
    public InverseModelListRef<LandMarkData, MapData> getLandMarkDataListRef() {
        return landMarkDataListRef;
    }


    /**
     * @return the memberDataListRef
     */
    public InverseModelListRef<MemberData, MapData> getMemberDataListRef() {
        return memberDataListRef;
    }

    public String getAdminMailAddress() {
        return adminMailAddress;
    }

    public void setAdminMailAddress(String adminMailAddress) {
        this.adminMailAddress = adminMailAddress;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public InverseModelListRef<LineData, MapData> getLineDataListRef() {
        return lineDataListRef;
    }

    public void setLineType(String lineType) {
        this.lineType = lineType;
    }

    public String getLineType() {
        return lineType;
    }

    public void setFromMailAddress(String fromMailAddress) {
        this.fromMailAddress = fromMailAddress;
    }

    public String getFromMailAddress() {
        return fromMailAddress;
    }

    public void setAccessLevel(String accessLevel) {
        this.accessLevel = accessLevel;
    }

    public String getAccessLevel() {
        return accessLevel;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getAccessKey() {
        return accessKey;
    }
}
